package com.xing.User.Action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.collections.map.HashedMap;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.google.gson.JsonArray;
import com.xing.User.Entity.User;
import com.xing.User.Service.UserService;

import net.sf.json.JSONArray;

/**
*@author xingxing
*@version 
*@time 2017年10月20日 上午9:47:53 
*class explain：
*/
@Controller//注解：说明是控制层
@Scope("prototype")//注解：作用范围
public class UserAction {
	private HttpServletResponse response = ServletActionContext.getResponse();//为了得到response,响应
	private HttpServletRequest request = ServletActionContext.getRequest();//为了得到request,请求
	@Autowired
	UserService userService;
	
	public void UserRoleList() throws IOException {
		List listjson = new ArrayList();
		HttpSession session= request.getSession();
		User user =(User)session.getAttribute("user");
		List<Object[]> list=(List<Object[]>)userService.querymenu(user.getId());
		for(Object[] obj :list) {
			System.out.println(obj[0]+" , "+obj[1]);
			Map map = new HashMap();
			map.put("Name", obj[0]);
			map.put("UrlAction", obj[1]);
			listjson.add(map);
		}
		JSONArray jsonArray=JSONArray.fromObject(listjson);
		response.getWriter().write(jsonArray.toString());
	}
}
